package com.fengchao.api.controller.v1;

import com.alibaba.fastjson.JSON;
import com.fengchao.api.service.MriService;
import com.fengchao.model.entity.comm.CustomBizException;
import com.fengchao.model.entity.comm.Message;
import com.fengchao.model.entity.comm.ResponseParameter;
import com.fengchao.model.mri.MriMv;
import com.fengchao.util.common.CommonValidator;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.fengchao.api.config.Constant.GET_SUCCESS;
import static com.fengchao.api.config.Constant.PARAMETER_IS_NOT_COMPLETE;

/**
 * 影视资源控制器
 * Created by wangnian on 2016/6/8.
 */
@RestController
@RequestMapping("/v1/mri")
public class MriController  {

    @Autowired
    private MriService mriService;

    private static Logger logger = LoggerFactory.getLogger(MriController.class);

    @RequestMapping(value = "/getSongs/{artistId}/{page}/{count}", method = RequestMethod.GET)
    @ApiOperation(value = "(APP/WEB)获取艺人的歌曲列表", notes = "返回参数</br>成功:</br>{status:SUCCESS, </br>message:获取成功,</br>data:{</br>&nbsp;&nbsp;total：8(歌曲总数),</br>&nbsp;&nbsp;info:[</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;songLink: http://aaa.png (歌曲链接),</br>&nbsp;&nbsp;&nbsp;&nbsp;songName: aaa(歌曲名字)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;songTime: 285(歌曲时长),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumName: aaa(专辑名),</br>&nbsp;&nbsp;&nbsp;&nbsp;songImageUrl: http://aaa.png (歌曲图片),</br>&nbsp;&nbsp;&nbsp;&nbsp;nameDisplay: 张靓颖(艺人展示名),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumId: 1(专辑ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;artistId: 1 (艺人ID)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;songType: 流行/哈哈(歌曲风格),</br>&nbsp;&nbsp;&nbsp;&nbsp;songId: 1(歌曲ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;songInfo: aaa(歌曲简介)</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>失败:</br>{status:FAILURE, message:参数不全}")
    public ResponseParameter getSongs(@ApiParam(value = "(APP/WEB必填)艺人id", required = true) @PathVariable("artistId") Integer artistId,
                                      @ApiParam(value = "(APP/WEB必填)第几页", required = true) @PathVariable("page") Integer page,
                                      @ApiParam(value = "(APP/WEB必填)显示多少行", required = true) @PathVariable("count") Integer count) {
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        logger.info("艺人歌曲请求参数=artistId:{}  page:{} count:{}", artistId, page, count);
        if (!CommonValidator.isStringsNotNull(artistId)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        List<Map<String, Object>> mriSongsList = mriService.findSongsList(artistId, page, count);
        Integer total = mriService.findSongsListTotal(artistId);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("info", mriSongsList);
        map.put("total", total);
        responseParameter.setData(map);

        logger.info("艺人歌曲响应参数= {}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    @RequestMapping(value = "/getMv/{artistId}/{page}/{count}", method = RequestMethod.GET)
    @ApiOperation(value = "(APP/WEB)获取艺人的MV列表", notes = "返回参数</br>成功:</br>{status:SUCCESS, </br>message:获取成功,</br>data:{</br>&nbsp;&nbsp;total：8(MV总数),</br>&nbsp;&nbsp;info:[</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;id: 1(MV的ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;artistId: 1(艺人ID)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;mvName: 演员(MV名称),</br>&nbsp;&nbsp;&nbsp;&nbsp;mvLink: http://aaa.png (MV链接),</br>&nbsp;&nbsp;&nbsp;&nbsp;mvTime: 285(专辑时长),</br>&nbsp;&nbsp;&nbsp;&nbsp;language: 国语(专辑语言),</br>&nbsp;&nbsp;&nbsp;&nbsp;mvInfo: aaa(MV简介),</br>&nbsp;&nbsp;&nbsp;&nbsp;mvType: 流行/哈哈(MV风格)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;mvImageUrl: http://aaa.png (MV的图片),</br>&nbsp;&nbsp;&nbsp;&nbsp;createTime: 1465710673000(MV的创建时间),</br>&nbsp;&nbsp;&nbsp;&nbsp;updateTime: 1464710400000(MV的更新时间),</br>&nbsp;&nbsp;&nbsp;&nbsp;deleted: false (是否删除, true: 是, false: 否)" +
            "</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>失败:</br>{status:FAILURE, message:参数不全}")
    public ResponseParameter getMv(@ApiParam(value = "(APP/WEB必填)艺人id", required = true) @PathVariable("artistId") Integer artistId,
                                   @ApiParam(value = "(APP/WEB必填)第几页", required = true) @PathVariable("page") Integer page,
                                   @ApiParam(value = "(APP/WEB必填)显示多少行", required = true) @PathVariable("count") Integer count) {
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        logger.info("艺人MV请求参数=artistId:{}  page:{} count:{}", artistId, page, count);
        if (!CommonValidator.isStringsNotNull(artistId, page, count)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        List<MriMv> mriMvList = mriService.findMvList(artistId, page, count);
        Integer total = mriService.findMvListTotal(artistId);

        HashMap<Object, Object> map = new HashMap<>();
        map.put("info", mriMvList);
        map.put("total", total);
        responseParameter.setData(map);
        logger.info("艺人MV响应参数= 总数量:{},分页数量:{}", total, mriMvList.size());
        logger.debug("艺人MV响应参数= {}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    @RequestMapping(value = "/getAlbum/{artistId}/{page}/{count}", method = RequestMethod.GET)
    @ApiOperation(value = "(APP/WEB)获取艺人的专辑列表", notes = "返回参数</br>成功:</br>{status:SUCCESS, </br>message:获取成功,</br>data:{</br>&nbsp;&nbsp;total：8(专辑总数),</br>&nbsp;&nbsp;info:[</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;publishCompany: 少城时代(发布公司),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumName: 童谣(专辑名称)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;albumInfo: aaa(专辑简介),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumImageUrl: http://aaa.png (专辑图片),</br>&nbsp;&nbsp;&nbsp;&nbsp;publishDate: 1464710400000(专辑发布时间),</br>&nbsp;&nbsp;&nbsp;&nbsp;language: 国语(专辑语言),</br>&nbsp;&nbsp;&nbsp;&nbsp;id: 1(专辑ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;songType: 流行/哈哈(专辑风格)" +
            "</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>失败:</br>{status:FAILURE, message:参数不全}")
    public ResponseParameter getAlbum(@ApiParam(value = "(APP/WEB必填)艺人id", required = true) @PathVariable("artistId") Integer artistId,
                                      @ApiParam(value = "(APP/WEB必填)第几页", required = true) @PathVariable("page") Integer page,
                                      @ApiParam(value = "(APP/WEB必填)显示多少行", required = true) @PathVariable("count") Integer count) {
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        logger.info("艺人专辑请求参数=artistId:{}  page:{} count:{}", artistId, page, count);
        if (!CommonValidator.isStringsNotNull(artistId, page, count)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        List<Map<String, Object>> mriAlbumList = mriService.findAlbumList(artistId, page, count);
        Integer total = mriService.findAlbumListTotal(artistId);

        HashMap<Object, Object> map = new HashMap<>();
        map.put("info", mriAlbumList);
        map.put("total", total);
        responseParameter.setData(map);
        logger.info("艺人专辑响应参数= 总数量:{},分页数量:{}", total, mriAlbumList.size());
        logger.debug("艺人专辑响应参数= {}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    @RequestMapping(value = "/getSongsByAlbum/{albumId}/{page}/{count}", method = RequestMethod.GET)
    @ApiOperation(value = "(APP/WEB)获取专辑的歌曲列表", notes = "返回参数</br>成功:</br>{status:SUCCESS, </br>message:获取成功,</br>data:{</br>&nbsp;&nbsp;total：8(歌曲总数),</br>&nbsp;&nbsp;info:[</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;songLink: http://aaa.png (歌曲链接),</br>&nbsp;&nbsp;&nbsp;&nbsp;songName: aaa(歌曲名字)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;songTime: 285(歌曲时长),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumName: aaa(专辑名),</br>&nbsp;&nbsp;&nbsp;&nbsp;songImageUrl: http://aaa.png (歌曲图片),</br>&nbsp;&nbsp;&nbsp;&nbsp;nameDisplay: 张靓颖(艺人展示名),</br>&nbsp;&nbsp;&nbsp;&nbsp;albumId: 1(专辑ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;artistId: 1 (艺人ID)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;songType: 流行/哈哈(歌曲风格),</br>&nbsp;&nbsp;&nbsp;&nbsp;songId: 1(歌曲ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;songInfo: aaa(歌曲简介)</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>失败:</br>{status:FAILURE, message:参数不全}")
    public ResponseParameter getSongsByAlbumList(@ApiParam(value = "(APP/WEB必填)专辑id", required = true) @PathVariable("albumId") Integer albumId,
                                                 @ApiParam(value = "(APP/WEB必填)第几页", required = true) @PathVariable("page") Integer page,
                                                 @ApiParam(value = "(APP/WEB必填)显示多少行", required = true) @PathVariable("count") Integer count) {
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        logger.info("专辑的歌曲请求参数=albumId:{}  page:{} count:{}", albumId, page, count);
        if (!CommonValidator.isStringsNotNull(albumId, page, count)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        List<Map<String, Object>> mriSongsList = mriService.findSongsByAlbumIdList(albumId, page, count);
        Integer total = mriService.findSongsByAlbumIdListTotal(albumId);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("info", mriSongsList);
        map.put("total", total);
        responseParameter.setData(map);
        logger.info("专辑的歌曲响应参数= 总数量:{},分页数量:{}", total, mriSongsList.size());
        logger.debug("专辑的歌曲响应参数= {}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    @RequestMapping(value = "/getSongsByAlbum/{albumId}", method = RequestMethod.GET)
    @ApiOperation(value = "(APP/WEB)获取专辑简介", notes = "返回参数</br>成功:</br>{status:SUCCESS, </br>message:获取成功,</br>data:{</br>&nbsp;&nbsp;info:{</br>&nbsp;&nbsp;&nbsp;publishCompany: 少城时代(专辑发布公司),</br>&nbsp;&nbsp;&nbsp;albumName: 童谣(专辑名称)," +
            "</br>&nbsp;&nbsp;&nbsp;albumInfo: aaa(专辑简介),</br>&nbsp;&nbsp;&nbsp;albumImageUrl: http://aaa.png (专辑图片),</br>&nbsp;&nbsp;&nbsp;publishDate: 1464710400000(专辑发布时间),</br>&nbsp;&nbsp;&nbsp;language: 国语(专辑语言),</br>&nbsp;&nbsp;&nbsp;artistId: 1(歌曲ID),</br>&nbsp;&nbsp;&nbsp;songType: 流行/哈哈(专辑风格)," +
            "</br>&nbsp;&nbsp;&nbsp;artistDisplay: 张靓颖(艺人展示名)</br>&nbsp;&nbsp;}</br>&nbsp;}</br>}" +
            "</br>失败:</br>{status:FAILURE, message:参数不全}")
    public ResponseParameter getSongsByAlbum(@ApiParam(value = "(APP/WEB必填)专辑id", required = true) @PathVariable("albumId") Integer albumId) {
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        logger.info("获取专辑简介请求参数=albumId:{}  page:{} count:{}", albumId);
        if (!CommonValidator.isStringsNotNull(albumId)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Map<String, Object> albumMap = mriService.findMriAlbumById(albumId);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("info", albumMap);
        responseParameter.setData(map);
        logger.info("专辑的歌曲响应参数= {}", JSON.toJSON(responseParameter));
        return responseParameter;
    }


}